<?php
/**
 * 程序: 工厂类
 * author: warpath
 * 2012年 09月 14日 星期五 07:50:52 PDT
 */
class Factory
{
	private static $_smarty  = null;
	private static $_dao     = null;

	/**
	 * desc:smarty模板
	 */
	public static function getSmarty()
	{
		if (empty(self::$_smarty)) {
			require(_LIBS_DIR_ . 'smarty/Smarty.class.php');
			self::$_smarty = new smarty();
			self::$_smarty->template_dir = _SITE_ROOT_ . '/templates/';
			self::$_smarty->compile_dir  = _SITE_ROOT_ . '/temp/templates_c/';
			self::$_smarty->cache_dir    = _SITE_ROOT_ . '/temp/cache/';
			self::$_smarty->cacheing     = false;
			self::$_smarty->left_delimiter = '<{';
			self::$_smarty->right_delimiter = '}>';

		}

		return self::$_smarty;
	}

	/**
	 * desc:DAO层
	 */
	public static function getDao($name)
	{
		if (empty(self::$_dao[$name])) {
			require_once(_INCLUDES_DIR_ . 'baseDao.php');
			try {
				//TODO::数据库表检查
				self::$_dao[$name] = new BaseDao();
				self::$_dao[$name]->_table = $name;
			} catch(Exception $e) {
				echo 'Caught exception: ', $e->getMessage(), "\n";
			}
		}

		return self::$_dao[$name];
	}


}
?>
